home *** CD-ROM | disk | FTP | other *** search
/ Postcardigtal: Baalbeck / postcardigtal: Baalbeck.iso / mac / fguidedtour.swf / scripts / FScrollPaneSymbol.as < prev    next >
Text File  |  2003-07-04  |  9KB  |  298 lines

  1. function FScrollPaneClass()
  2. {
  3.    function boolToString(str)
  4.    {
  5.       if(str == "false")
  6.       {
  7.          return false;
  8.       }
  9.       if(str == "true")
  10.       {
  11.          return true;
  12.       }
  13.       return str;
  14.    }
  15.    this.init();
  16.    this.width = this._width;
  17.    this.height = this._height;
  18.    this._xscale = this._yscale = 100;
  19.    this.contentWidth = this.contentHeight = 0;
  20.    if(this.hScroll == undefined)
  21.    {
  22.       this.hScroll = this.vScroll = "auto";
  23.       this.dragContent = false;
  24.    }
  25.    this.offset = new Object();
  26.    this.vScroll = boolToString(this.vScroll);
  27.    this.hScroll = boolToString(this.hScroll);
  28.    this.attachMovie("FScrollBarSymbol","hScrollBar_mc",100,{hostStyle:this.styleTable});
  29.    this.hScrollBar_mc.setHorizontal(true);
  30.    this.hScrollBar_mc.setSmallScroll(5);
  31.    this.hScrollBar_mc.setChangeHandler("onScroll",this);
  32.    this.attachMovie("FScrollBarSymbol","vScrollBar_mc",99,{hostStyle:this.styleTable});
  33.    this.vScrollBar_mc.setSmallScroll(5);
  34.    this.vScrollBar_mc.setChangeHandler("onScroll",this);
  35.    this.setSize(this.width,this.height);
  36.    if(this.scrollContent != "")
  37.    {
  38.       this.setScrollContent(this.scrollContent);
  39.    }
  40.    this.setDragContent(this.dragContent);
  41. }
  42. FScrollPaneClass.prototype = new FUIComponentClass();
  43. Object.registerClass("FScrollPaneSymbol",FScrollPaneClass);
  44. FScrollPaneClass.prototype.getScrollContent = function()
  45. {
  46.    return this.content_mc;
  47. };
  48. FScrollPaneClass.prototype.getPaneWidth = function()
  49. {
  50.    return this.width;
  51. };
  52. FScrollPaneClass.prototype.getPaneHeight = function()
  53. {
  54.    return this.height;
  55. };
  56. FScrollPaneClass.prototype.getScrollPosition = function()
  57. {
  58.    var xPos = this.hScrollBar_mc != undefined ? this.hScrollBar_mc.getScrollPosition() : 0;
  59.    var yPos = this.vScrollBar_mc != undefined ? this.vScrollBar_mc.getScrollPosition() : 0;
  60.    return {x:xPos,y:yPos};
  61. };
  62. FScrollPaneClass.prototype.setScrollContent = function(target)
  63. {
  64.    this.offset.x = 0;
  65.    this.offset.y = 0;
  66.    if(this.content_mc != undefined)
  67.    {
  68.       if(target != this.content_mc)
  69.       {
  70.          this.content_mc._visible = false;
  71.          this.content_mc.removeMovieClip();
  72.          this.content_mc.unloadMovie();
  73.       }
  74.    }
  75.    if(typeof target == "string")
  76.    {
  77.       this.attachMovie(target,"tmp_mc",3);
  78.       this.content_mc = this.tmp_mc;
  79.    }
  80.    else if(target == undefined)
  81.    {
  82.       this.content_mc.unloadMovie();
  83.    }
  84.    else
  85.    {
  86.       this.content_mc = target;
  87.    }
  88.    this.localToGlobal(this.offset);
  89.    this.content_mc._parent.globalToLocal(this.offset);
  90.    this.content_mc._x = this.offset.x;
  91.    this.content_mc._y = this.offset.y;
  92.    var contentBounds = this.content_mc.getBounds(this);
  93.    this.offset.x = - contentBounds.xMin;
  94.    this.offset.y = - contentBounds.yMin;
  95.    this.localToGlobal(this.offset);
  96.    this.content_mc._parent.globalToLocal(this.offset);
  97.    this.content_mc._x = this.offset.x;
  98.    this.content_mc._y = this.offset.y;
  99.    this.contentWidth = this.content_mc._width;
  100.    this.contentHeight = this.content_mc._height;
  101.    this.content_mc.setMask(this.mask_mc);
  102.    this.setSize(this.width,this.height);
  103. };
  104. FScrollPaneClass.prototype.setSize = function(w, h)
  105. {
  106.    if(arguments.length < 2 || isNaN(w) || isNaN(h))
  107.    {
  108.       return undefined;
  109.    }
  110.    super.setSize(w,h);
  111.    this.width = Math.max(w,60);
  112.    this.height = Math.max(h,60);
  113.    this.boundingBox_mc._xscale = 100;
  114.    this.boundingBox_mc._yscale = 100;
  115.    this.boundingBox_mc._width = this.width;
  116.    this.boundingBox_mc._height = this.height;
  117.    this.setHandV();
  118.    this.initScrollBars();
  119.    if(this.mask_mc == undefined)
  120.    {
  121.       this.attachMovie("FBoundingBoxSymbol","mask_mc",3000);
  122.    }
  123.    this.mask_mc._xscale = 100;
  124.    this.mask_mc._yscale = 100;
  125.    this.mask_mc._width = this.hWidth;
  126.    this.mask_mc._height = this.vHeight;
  127.    this.mask_mc._alpha = 0;
  128. };
  129. FScrollPaneClass.prototype.setScrollPosition = function(x, y)
  130. {
  131.    x = Math.max(this.hScrollBar_mc.minPos,x);
  132.    x = Math.min(this.hScrollBar_mc.maxPos,x);
  133.    y = Math.max(this.vScrollBar_mc.minPos,y);
  134.    y = Math.min(this.vScrollBar_mc.maxPos,y);
  135.    this.hScrollBar_mc.setScrollPosition(x);
  136.    this.vScrollBar_mc.setScrollPosition(y);
  137. };
  138. FScrollPaneClass.prototype.refreshPane = function()
  139. {
  140.    this.setScrollContent(this.content_mc);
  141. };
  142. FScrollPaneClass.prototype.loadScrollContent = function(url, handler, location)
  143. {
  144.    this.content_mc.removeMovieClip();
  145.    this.content_mc.unloadMovie();
  146.    this.content_mc._visible = 0;
  147.    this.loadContent.duplicateMovieClip("loadTemp",3);
  148.    this.dupeFlag = true;
  149.    this.contentLoaded = function()
  150.    {
  151.       this.loadReady = false;
  152.       this.content_mc = this.loadTemp;
  153.       this.refreshPane();
  154.       this.executeCallBack();
  155.    };
  156.    this.setChangeHandler(handler,location);
  157.    this.loadTemp.loadMovie(url);
  158. };
  159. FScrollPaneClass.prototype.setHScroll = function(prop)
  160. {
  161.    this.hScroll = prop;
  162.    this.setSize(this.width,this.height);
  163. };
  164. FScrollPaneClass.prototype.setVScroll = function(prop)
  165. {
  166.    this.vScroll = prop;
  167.    this.setSize(this.width,this.height);
  168. };
  169. FScrollPaneClass.prototype.setDragContent = function(dragFlag)
  170. {
  171.    if(dragFlag)
  172.    {
  173.       this.boundingBox_mc.useHandCursor = true;
  174.       this.boundingBox_mc.onPress = function()
  175.       {
  176.          this._parent.startDragLoop();
  177.       };
  178.       this.boundingBox_mc.tabEnabled = false;
  179.       this.boundingBox_mc.onRelease = this.boundingBox_mc.onReleaseOutside = function()
  180.       {
  181.          this._parent.pressFocus();
  182.          this._parent.onMouseMove = null;
  183.       };
  184.    }
  185.    else
  186.    {
  187.       delete this.boundingBox_mc.onPress;
  188.       this.boundingBox_mc.useHandCursor = false;
  189.    }
  190. };
  191. FScrollPaneClass.prototype.setSmallScroll = function(x, y)
  192. {
  193.    this.hScrollBar_mc.setSmallScroll(x);
  194.    this.vScrollBar_mc.setSmallScroll(y);
  195. };
  196. FScrollPaneClass.prototype.setHandV = function()
  197. {
  198.    if(this.contentHeight - this.height > 2 && this.vScroll != false || this.vScroll == true)
  199.    {
  200.       this.hWidth = this.width - this.vScrollBar_mc._width;
  201.    }
  202.    else
  203.    {
  204.       this.hWidth = this.width;
  205.    }
  206.    if(this.contentWidth - this.width > 2 && this.hScroll != false || this.hScroll == true)
  207.    {
  208.       this.vHeight = this.height - this.hScrollBar_mc._height;
  209.    }
  210.    else
  211.    {
  212.       this.vHeight = this.height;
  213.    }
  214. };
  215. FScrollPaneClass.prototype.startDragLoop = function()
  216. {
  217.    this.tabFocused = false;
  218.    this.myOnSetFocus();
  219.    this.lastX = this._xmouse;
  220.    this.lastY = this._ymouse;
  221.    this.onMouseMove = function()
  222.    {
  223.       this.scrollXMove = this.lastX - this._xmouse;
  224.       this.scrollYMove = this.lastY - this._ymouse;
  225.       this.scrollXMove += this.hScrollBar_mc.getScrollPosition();
  226.       this.scrollYMove += this.vScrollBar_mc.getScrollPosition();
  227.       this.setScrollPosition(this.scrollXMove,this.scrollYMove);
  228.       if(this.scrollXMove < this.hScrollBar_mc.maxPos && this.scrollXMove > this.hScrollBar_mc.minPos)
  229.       {
  230.          this.lastX = this._xmouse;
  231.       }
  232.       if(this.scrollYMove < this.vScrollBar_mc.maxPos && this.scrollYMove > this.vScrollBar_mc.minPos)
  233.       {
  234.          this.lastY = this._ymouse;
  235.       }
  236.       this.updateAfterEvent();
  237.    };
  238. };
  239. FScrollPaneClass.prototype.initScrollBars = function()
  240. {
  241.    this.hScrollBar_mc._y = this.height - this.hScrollBar_mc._height;
  242.    this.hScrollBar_mc.setSize(this.hWidth);
  243.    this.hScrollBar_mc.setScrollProperties(this.hWidth,0,this.contentWidth - this.hWidth);
  244.    this.vScrollBar_mc._visible = this.hWidth != this.width ? true : false;
  245.    this.vScrollBar_mc._x = this.width - this.vScrollBar_mc._width;
  246.    this.vScrollBar_mc.setSize(this.vHeight);
  247.    this.vScrollBar_mc.setScrollProperties(this.vHeight,0,this.contentHeight - this.vHeight);
  248.    this.hScrollBar_mc._visible = this.vHeight != this.height ? true : false;
  249. };
  250. FScrollPaneClass.prototype.onScroll = function(component)
  251. {
  252.    var pos = component.getScrollPosition();
  253.    var XorY = component._name != "hScrollBar_mc" ? "y" : "x";
  254.    if(component._name == "hScrollBar_mc")
  255.    {
  256.       this.content_mc._x = - pos + this.offset.x;
  257.    }
  258.    else
  259.    {
  260.       this.content_mc._y = - pos + this.offset.y;
  261.    }
  262. };
  263. FScrollPaneClass.prototype.myOnKeyDown = function()
  264. {
  265.    var posX = this.hScrollBar_mc.getScrollPosition();
  266.    var posY = this.vScrollBar_mc.getScrollPosition();
  267.    if(this.hScrollBar_mc.maxPos > this.hScrollBar_mc.minPos)
  268.    {
  269.       if(Key.isDown(37))
  270.       {
  271.          this.setScrollPosition(posX - 3,posY);
  272.       }
  273.       else if(Key.isDown(39))
  274.       {
  275.          this.setScrollPosition(posX + 3,posY);
  276.       }
  277.    }
  278.    if(this.vScrollBar_mc.maxPos > this.vScrollBar_mc.minPos)
  279.    {
  280.       if(Key.isDown(38))
  281.       {
  282.          this.setScrollPosition(posX,posY - 3);
  283.       }
  284.       else if(Key.isDown(40))
  285.       {
  286.          this.setScrollPosition(posX,posY + 3);
  287.       }
  288.       else if(Key.isDown(34))
  289.       {
  290.          this.setScrollPosition(posX,posY + this.vScrollBar_mc.pageSize);
  291.       }
  292.       else if(Key.isDown(33))
  293.       {
  294.          this.setScrollPosition(posX,posY - this.vScrollBar_mc.pageSize);
  295.       }
  296.    }
  297. };
  298.